﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace SchoolManagementSystem
{
    public partial class AkunAdd : Form
    {
        private Akun parent = null;

        public AkunAdd()
        {
            InitializeComponent();
        }

        public AkunAdd(Akun instance)
        {
            InitializeComponent();
            parent = instance;
        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if ((this.akun.Text == "") || (this.username.Text == "") || (this.password.Text == "") ||
                (this.repassword.Text == "") || (this.contact.Text == "") || (this.type.Text == ""))
            {
                MessageBox.Show("Tidak boleh ada data yang kosong", "Peringatan !");
            }
            else if (this.password.Text != this.repassword.Text)
            {
                MessageBox.Show("Password dan ulangi password tidak sama", "Peringatan !");
            }
            else
            {
                Database.getInstance().accountAdd(this.akun.Text, this.username.Text, this.password.Text, this.contact.Text, this.type.Text);
                var result = MessageBox.Show("Tambah akun berhasil", "Success");
                if (result == System.Windows.Forms.DialogResult.OK)
                {
                    this.Close();
                    if(this.parent != null) 
                        this.parent.update();
                    // Database.getInstance().logSistem(Database.Log_ID.AccountAdd, "Menambah akun ke sistem");
                }
            }
            
        }

        private void AkunAdd_Load(object sender, EventArgs e)
        {

        }
    }
}
